package de.mfits.fireflyplayer;

import static de.mfits.fireflyplayer.storage.DbHelper.ALBUM;
import static de.mfits.fireflyplayer.storage.DbHelper.ARTIST;
import static de.mfits.fireflyplayer.storage.DbHelper.ID;
import static de.mfits.fireflyplayer.storage.DbHelper.SONGS;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class BrowseAlbumsActivity extends BrowseActivity {

  private static final String TRACKS = "tracks";

  private static final String TABLE = SONGS;
  private static final String[] COLUMNS = { ALBUM + " as " + ID,
      "min(" + ARTIST + ") as " + ARTIST, ALBUM, "count(*) as " + TRACKS };
  private static final String SELECTION = null;
  private static final String GROUP_BY = ALBUM;
  private static final String HAVING = null;
  private static final String ORDER_BY = ARTIST;

  private static final int LAYOUT = R.layout.list_albums;
  private static final String[] FROM = { ALBUM, ARTIST, TRACKS };
  private static final int[] TO = { R.id.album, R.id.albumArtist, R.id.albumTracks };

  public BrowseAlbumsActivity() {
    super(TABLE, COLUMNS, SELECTION, GROUP_BY, HAVING, ORDER_BY, LAYOUT, FROM, TO);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.browse_title_albums);
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    cursor.moveToPosition(position);
    String album = cursor.getString(cursor.getColumnIndex(ALBUM));

    Intent intent = new Intent(this, BrowseAlbumSongsActivity.class);
    intent.putExtra(ALBUM, album);
    startActivity(intent);
  }
}
